package com.zm.demo.core.leetcode;

import static java.lang.System.out;

/**
 * @author zoum
 * @create 2020/1/9 15:16
 */
public class HasPathSum {


    public boolean hasPathSum(TreeNode root, int sum) {
        sum -= root.val;
        if (sum == 0 && root.left == null && root.right == null){
            return true;
        }else {
            if (root.left != null && hasPathSum(root.left, sum)){
                return true;
            }
            if (root.right != null && hasPathSum(root.right, sum)){
                return true;
            }
        }
        return false;
    }

    public static void main(String[]args){

        TreeNode node1 = new TreeNode(-2);
        TreeNode node2 = new TreeNode(-3);
//        TreeNode node3 = new TreeNode(3);
//        TreeNode node4 = new TreeNode(4);
//        TreeNode node5 = new TreeNode(5);
        node1.right = node2;
//        node2.right = node3;
//        node3.right = node4;
//        node4.right = node5;


        out.println(new HasPathSum().hasPathSum(node1, -5));
    }
}
